package com.idconfirmsystem.adapter;

import java.util.List;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.TextView;

import com.idconfirmsystem.R;
import com.idconfirmsystem.lib.StringUtil;
import com.idconfirmsystem.model.BagVerifyInfo;

public class BagVerifyQueryAdapter extends BaseAdapter {
	private List<BagVerifyInfo> baglist;

	private Context context;
	ListView listView;

	public BagVerifyQueryAdapter(Context context, ListView listView) {
		this.context = context;
		this.listView = listView;
	}

	public BagVerifyQueryAdapter(Context context, ListView listView, List<BagVerifyInfo> baglist) {
		this.context = context;
		this.listView = listView;
		this.baglist = baglist;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return baglist == null ? 0 : baglist.size();
	}

	@Override
	public Object getItem(int arg0) {
		// TODO Auto-generated method stub
		return baglist.get(arg0);
	}

	@Override
	public long getItemId(int arg0) {
		// TODO Auto-generated method stub
		return arg0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		final ViewHolder viewHolder;
		if (convertView == null) {
			viewHolder = new ViewHolder();
			convertView = View.inflate(context, R.layout.item_querybag, null);
			viewHolder.tvBagInfo = (TextView) convertView.findViewById(R.id.tv_bagInfo);
			viewHolder.tvBranchInfo = (TextView) convertView.findViewById(R.id.tv_branchinfo);
			viewHolder.tvIsVerify = (TextView) convertView.findViewById(R.id.tv_isverify);
			viewHolder.tvVerifyTime = (TextView) convertView.findViewById(R.id.tv_verify_time);
			convertView.setTag(viewHolder);
		} else {
			viewHolder = (ViewHolder) convertView.getTag();
		}
		BagVerifyInfo item = baglist.get(position);
		viewHolder.tvBranchInfo.setText("网点：" + item.getBranch_number() + item.getCoordinate_title());
		String bginfo = "箱（包）号：" + item.getBags_number();
		if (!StringUtil.isEmpty(item.getBags_seal_no())) {
			bginfo += " 签封号：" + item.getBags_seal_no();
		}
		viewHolder.tvBagInfo.setText(bginfo);
		bginfo = "";
		if (item.getVerifyFlag() == "1") {
			bginfo = "已核验";
			viewHolder.tvVerifyTime.setText(item.getVerifyTime());
			convertView.findViewById(R.id.iv_tip).setVisibility(View.GONE);
			viewHolder.tvIsVerify.setText(bginfo);
		} else {
			bginfo = "未核验";
			convertView.findViewById(R.id.iv_tip).setVisibility(View.VISIBLE);
			viewHolder.tvIsVerify.setText(bginfo);
		}

		return convertView;
	}

	public List<BagVerifyInfo> getBaglist() {
		return baglist;
	}

	public void setBaglist(List<BagVerifyInfo> baglist) {
		this.baglist = baglist;
	}

	public class ViewHolder {
		public TextView tvBranchInfo;
		public TextView tvBagInfo;
		public TextView tvIsVerify;
		public TextView tvVerifyTime;
	}
}
